package com.zhang.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.zhang.entity.response.ResponseResult;
import com.zhang.entity.vo.UpdateUserBody;
import com.zhang.entity.vo.UpdateUserMessageBody;
import com.zhang.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * User: 张
 * Date: 2024-10-31
 * Time: 10:08
 * Description:
 */
@RestController()
@RequestMapping("/normal")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/updateUserMessage")
    public ResponseResult<String> updateUserMessage(@RequestBody UpdateUserMessageBody updateUserMessageBody) {
        UpdateUserBody updateUserBody = new UpdateUserBody(
                StpUtil.getLoginIdAsInt(),
                updateUserMessageBody.getUserName(),
                updateUserMessageBody.getPhone(),
                updateUserMessageBody.getImageId(),
                updateUserMessageBody.getEmail()
        );
        return userService.updateUser(updateUserBody) ? ResponseResult.success() : ResponseResult.error();
    }

    @GetMapping("/getMyAuthority")
    public ResponseResult<Object> getMyAuthority(){
        return ResponseResult.success(userService.getMyAuthority(StpUtil.getLoginIdAsInt()));
    }

    @GetMapping("/getMyMessage")
    public ResponseResult<Object> getMyMessage(){
        return ResponseResult.success(userService.getMyMessage(StpUtil.getLoginIdAsInt()));
    }





}
